import org.junit.Test;

import java.io.UnsupportedEncodingException;
import java.util.ArrayList;

public class test {
    // 1
    public boolean Find(int target, int[][] array) {
        boolean bol = false;
        for (int[] item : array) {
            for (int i : item) {
                if (i == target) {
                    bol = true;
                }
            }
        }
        return bol;
    }
    public boolean Find1(int target, int[][] array) {
        boolean bol = false;
        int min1 = 0;
        int max1= array.length - 1;
        int mid1 = (max1+min1)/2;
        return bol;
    }

    @Test
    public void test1() throws UnsupportedEncodingException {
        String a = "abc";
        recursion(a.toCharArray(),0);
    }

    public void recursion(char[] chars, int i){
        if (i>=chars.length||i<0){
            return;
        }
        if (i==chars.length-1){
            System.out.println(chars);
        }else {
            for (int j=i;j<chars.length;j++){
                swap(chars,i,j);
                recursion(chars,i+1);
                swap(chars,i,j);
            }
        }

    }

    public void swap(char[] chars,int i,int j){
        System.out.println(i+"-"+j);
        char temp = chars[j];
        chars[j] = chars[i];
        chars[i] = temp;
    }

    public int operation(int [] array){
        int len = array.length; // 数组总长度
        int index=len; // 满足条件的下标
        int[] num = new int[len]; // /存放次数的数组
        for (int i = 0;i<=len-1;i++){
            for (int j = 0;j<=len-1;j++){
                if (array[i]==array[j]){
                    num[i]++;
                    if (num[i]>len/2){
                        index = i;
                        return array[i];
                    }
                }
            }
        }
        if (index==len){
            return 0;
        }else {
            return array[index];
        }
    }
    @Test
    public void test2(){
//        int s [] = {1,2,3,2,4,2,5,2,3};
          int s [] = {1,2,3,2,2,2,5,4,2};
          System.out.println(operation(s));
    }



}
